﻿using MachineVision.Extensions;
using MachineVision.Models;
using Prism.Mvvm;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MachineVision.Services
{
    public class NavigationMenuService : BindableBase,INavigationMenuService
    {
        public NavigationMenuService()
        {
            this.Items = new ObservableCollection<NavigationItem>();
        }

        private ObservableCollection<NavigationItem> items;

        public ObservableCollection<NavigationItem> Items
        {
            get { return items; }
            set { items = value; }
        }

        public void InitMenus()
        {
            Items.Clear();

            Items.Add(new NavigationItem("", "All", "全部", "", new ObservableCollection<NavigationItem>()
            {
                new NavigationItem("","TemplateMatch", "模版匹配","", new ObservableCollection<NavigationItem>()
                {
                    new NavigationItem("ShapeOutline","shapeMatch", "形状匹配","ShapeView"),
                    new NavigationItem("Clouds","NccMacth", "相似性匹配","NccView"),
                    new NavigationItem("ShapeOvalPlus","DeformationMatch", "形变匹配",""),
                }),
                new NavigationItem("","Measure", "比较测量","", new ObservableCollection<NavigationItem>()
                {
                    new NavigationItem("Circle","Caliper", "卡尺找圆",""),
                    new NavigationItem("Palette","Color", "颜色检测",""),
                    new NavigationItem("Ruler","GeometricMeasurement", "几何测量",""),
                }),
                new NavigationItem("","Character", "字符识别","", new ObservableCollection<NavigationItem>()
                {
                    new NavigationItem("FormatColorText","Character", "字符识别",""),
                    new NavigationItem("Barcode","BarCode", "一维码识别","BarCodeView"),
                    new NavigationItem("Qrcode","QrCode", "二维码识别","QrCodeView"),
                }),
                new NavigationItem("","Defect", "缺陷检测","", new ObservableCollection<NavigationItem>()
                {
                    new NavigationItem("Crop","Difference", "差分模型",""),
                    new NavigationItem("CropRotate","Deformable", "形变模型",""),
                }),

            }));

            Items.Add(new NavigationItem("", "TemplateMatch", "模版匹配", ""));
            Items.Add(new NavigationItem("", "Measure", "比较测量", ""));
            Items.Add(new NavigationItem("", "Defect", "缺陷检测", ""));
            Items.Add(new NavigationItem("", "Document", "学习文档", ""));
            Items.Add(new NavigationItem("", "Setting", "系统设置", "SettingView"));
        }

        public void RefreshMenus()
        {
            foreach (var item in Items)
            {
                item.Name = LanguageHelper.KeyValues[item.Key];
                //这里只筛选出Items[0]
                if (item.Items!=null && item.Items.Count > 0)
                {
                    foreach (var subItem in item.Items)
                    {
                        subItem.Name = LanguageHelper.KeyValues[subItem.Key];
                        if (subItem.Items != null && subItem.Items.Count > 0)
                        {
                            foreach (var other in subItem.Items)
                            {
                                other.Name = LanguageHelper.KeyValues[other.Key];
                            }
                        }
                    }
                }
            }
        }
    }
}
